'use strict';

import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
  *indexAction(){
    //auto render template file index_index.html
    let base = {};
    base.appId = this.get("app_id");
    base.openid = this.get("openid");
    base.service = parseInt(this.get('service'));
    let users = '';
    if(base.service == 1){
    	users = yield this.model("members").where(base).find();
    }else{
    	base.nickname = this.get('nickname');
	    /*昵称或临时昵称*/
  		if(think.isEmpty(base.nickname)){
  			var socketaArr = thinkCache(thinkCache.WEBSOCKET,'MYWEBSOCKETS');
        if(socketaArr && socketaArr.length>0){
          base.nickname = socketaArr.length+1000;
        }else{
          base.nickname = 1000;
        }
  		}
  		users = base;
    }
    
    console.log(users)
    this.assign("users",users);
    return this.display();
  }
}